package com.xiaoyu.commonlib.utils;

import android.content.Context;
import android.os.Looper;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.xiaoyu.commonlib.R;

public class ToastUtil {

    /**
     * 自定义样式的吐司
     * <p/>
     * 静态toast 只创建一个toast实例 可以实时显示弹出的内容
     *
     * @param context
     * @param text
     */
    public static void showToast(Context context, String text) {
        Toast toast = new Toast(context);
        // 获取打气筒
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //创建视图
        View view = inflater.inflate(R.layout.toast_item, null);
        TextView textView = (TextView) view.findViewById(R.id.tv_toast_text);
        textView.setText(text);

        //设置居中方式  默认在底部
        toast.setGravity(Gravity.CENTER, 0, 0);//如果不设置剧中方式,使用系统默认的吐司位置
        //设置土司的持续时长
        toast.setDuration(Toast.LENGTH_SHORT);
        //设置土司的背景View
        toast.setView(view);

        //设置土司的显示额内容
        toast.show();
    }


    /**
     * 自定义样式的吐司
     * <p/>
     * 静态toast 只创建一个toast实例 可以实时显示弹出的内容
     *
     * @param context
     * @param text
     */
    public static void showBelowToast(Context context, String text) {
        Toast toast = new Toast(context);
        // 获取打气筒
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //创建视图
        View view = inflater.inflate(R.layout.toast_item, null);
        TextView textView = (TextView) view.findViewById(R.id.tv_toast_text);
        textView.setText(text);

        //设置居中方式  默认在底部
//        toast.setGravity(Gravity.CENTER, 0, 0);//如果不设置剧中方式,使用系统默认的吐司位置
        //设置土司的持续时长
        toast.setDuration(Toast.LENGTH_SHORT);
        //设置土司的背景View
        toast.setView(view);

        //设置土司的显示额内容
        toast.show();
    }

    public static void showImgTosat(Context context, int toastNum) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View toast_layout = inflater.inflate(R.layout.toast_img_item, null);
        ImageView toastImg = toast_layout.findViewById(R.id.tv_toast_img);
        if (toastNum == 1) {
            toastImg.setImageResource(R.mipmap.zhuce_bg_v);
        }

        if (toastNum == 2) {
            toastImg.setImageResource(R.mipmap.xiugai_bg_v);
        }
        if (toastNum == 3) {
            toastImg.setImageResource(R.mipmap.audit);
        }
        if (toastNum == 4) {
            toastImg.setImageResource(R.mipmap.confirm);
        }

        Toast toast = new Toast(context);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.setView(toast_layout);
        toast.show();
    }

    /**
     * 接口失败打印
     *
     * @param interfaceName 接口的描述
     * @param errorCode     错误码
     * @param errorDescribe 错误描述
     */
    public static void logError(String interfaceName, String errorCode, String errorDescribe) {
        Log.i("xiaoyuu", interfaceName + "    errorCode = " + errorCode + "     errorDescribe = " + errorDescribe);
    }

    /**
     * 接口成功打印
     *
     * @param interfaceName
     * @param result
     */
    public static void logResult(String interfaceName, String result) {
        Log.i("xiaoyuu", interfaceName + "    result = " + result);
    }


    public static void log(String result) {
        Log.i("xiaoyuu", "    result = " + result);
    }
}
